<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm" :errorType="errorType">
			<u-form-item :label-position="labelPosition" label="机构名称" prop="name" label-width="150">
				<u-input :border="border" placeholder="请填写您的机构名称" v-model="model.name" type="text"></u-input>
			</u-form-item>
			<u-form-item :label-position="labelPosition" label="电话" prop="name" label-width="150">
				<u-input :border="border" placeholder="请填写客服电话,方便客服联系" v-model="model.phone" type="number"></u-input>
			</u-form-item>
			<u-form-item :label-position="labelPosition" label="所在地区" prop="region" label-width="150">
				<u-input :border="border" type="select" :select-open="pickerShow" v-model="model.region" placeholder="请选择地区" @click="pickerShow = true"></u-input>
			</u-form-item>
			<u-form-item :label-position="labelPosition" label="详细地址" prop="name" label-width="150">
				<u-input :border="border" placeholder="请填写详细地址,如街道门牌号" v-model="model.ditailsposition" type="text"></u-input>
			</u-form-item>
			<u-form-item :label-position="labelPosition" label="机构简介" prop="intro" label-width="150">
				<u-input type="textarea" :border="border" placeholder="请填写机构介绍,提升机构品牌" v-model="model.intro" />
			</u-form-item>
		</u-form>
		
		<view class="submit">
			<u-button @click="submit" type="warning" :ripple="true">提交</u-button>
		</view>
		
		<u-picker mode="region" v-model="pickerShow" @confirm="regionConfirm"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			let that = this;
			return {
				model: {
					name: '',
					phone: '',
					region: '',
					ditailsposition: '',
					intro: '',
				},
				pickerShow: false,
				border: false,
				actionSheetShow: false,
				labelPosition: 'left',
				errorType: ['message'],
			};
		},
		onShow() {
			
		},
		methods: {
			// 选择地区回调
			regionConfirm(e) {
				this.model.region = e.province.label + '-' + e.city.label + '-' + e.area.label;
			},
			submit () {
				if (!this.model.name) {
					uni.showToast({
						title: '请填写机构名称',
						icon: 'none'
					})
					return
				}
				if (!this.model.phone) {
					uni.showToast({
						title: '请填写客服电话',
						icon: 'none'
					})
					return
				}
				uni.request({ // 获取分享的二维码图片等信息
					url: 'https://www.xiaonengxinxi.com/app/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=goods.detail.apply&app=1',
					method: 'POST',
					data: {
						'name': this.model.name,
						'mobile':this.model.phone,
						'address':this.model.region + this.model.ditailsposition,
						'desc':this.model.intro,
						'openid':this.openid,
					},
					header:{
						'Content-Type':'application/x-www-form-urlencoded'
					},
					success: (res) => {
						uni.showToast({
							title: res.data.message
						})
						if (res.data.error == 0) {
							setTimeout(()=> {
								uni.navigateTo({
									url: '../user/user'
								})
							}, 1200);
						}
					}
				})
			}
		}
	};
</script>

<style>
	.wrap {
		padding: 30rpx;
	}
	.submit {
		margin-top: 400upx;
	}
</style>
